package ${pro.basePath}.service.impl;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import ${pro.entityPath}.${bean.entityName};
import ${pro.basePath}.mappers.${bean.entityName}Mapper;
import ${pro.basePath}.service.I${bean.entityName}Service;
import com.neusoft.utils.page.PageFactory;
@Service
@Transactional
public class ${bean.entityName}ServiceImpl  implements I${bean.entityName}Service{
   @Resource
	private ${bean.entityName}Mapper ${bean.entityName?uncap_first}Mapper;
	@Override
	public   int deleteById(${bean.idType} ${bean.idName}) {
		return ${bean.entityName?uncap_first}Mapper.deleteById(${bean.idName});
	}

	@Override
	public int save(${bean.entityName} bean) {
		return ${bean.entityName?uncap_first}Mapper.insert(bean);
	}

	@Override
	public int updateById(${bean.entityName} bean) {
		return ${bean.entityName?uncap_first}Mapper.updateById(bean);
	}

	@Override
	public ${bean.entityName} queryById(${bean.idType} ${bean.idName}) {
		return ${bean.entityName?uncap_first}Mapper.queryById(${bean.idName});
	}

	@Override
	public List<${bean.entityName}> queryList(Map<String, Object> param) {
		if(null==param){
			param= new HashMap<String, Object>();
		}
		if(null==param.get("isDelete")){
			param.put("isDelete",0);
		}
		return ${bean.entityName?uncap_first}Mapper.queryList(param);
	}

	@Override
	public Page<${bean.entityName}> queryPage(Map<String, Object> param, Pageable page) {
		if(null==param){
			param= new HashMap<String, Object>();
		}
		if(null==param.get("isDelete")){
			param.put("isDelete",0);
		}
		int count=${bean.entityName?uncap_first}Mapper.queryPageCount(param);
		List<${bean.entityName}> list=${bean.entityName?uncap_first}Mapper.queryPage(param, page);
		return PageFactory.createPage(list, page, count);
	}
	@Override
	public int saveOrUpdate(${bean.entityName} bean) {
		if(null==bean){
	     	return -1;
		}
		if(null!=bean.get${bean.idName?cap_first}()){
		    return updateById(bean);
		}
		return save(bean);
	}

}